package com.lc.afbx.conn;

import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/7/5.
 */
@HttpInlet(Conn.INLET_API_INSURANCE_ACCIDENT)
public class GetApiInsuranceAccident extends BaseAsyGet<GetApiInsuranceAccident.Info> {
    public String cid;

    public GetApiInsuranceAccident(AsyCallBack<GetApiInsuranceAccident.Info> asyCallBack) {
        super(asyCallBack);
    }

    protected Info parser(JSONObject jsonObject) {

        TOAST = jsonObject.optString("message");

        if (jsonObject.optInt("code") == 200) {

            JSONArray array = jsonObject.optJSONArray("data");

            Info info = new Info();
            for (int i = 0; i < array.length(); i++) {
                JSONObject o = array.optJSONObject(i);

                Data data = new Data();
                data.id = o.optString("id");
                data.title = o.optString("title");
                data.picurl = Conn.PIC + o.optString("picurl");

                info.dataList.add(data);
            }
            return info;
        }

        return null;
    }

    public static class Info {

        public List<Data> dataList = new ArrayList<>();
    }

    public static class Data {

        public String id, title, picurl;
    }
}
